const promise1 = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve('promise1');
  }, 1000);
});

const promise2 = new Promise((resolve, reject) => {
  setTimeout(() => {
    reject(new Error('promise2'));
  }, 500);
});

const promise3= new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve('promise3');
  }, 300);
});

// 1.055 seconds 并行 同时进行的请求
// promise 最多支持的并发数 浏览器限制6个并发
// [promise1, promise2, promise3] 如果有一个错误就会抛出错误
// Promise.all([promise1, promise2, promise3]).then(values => {
//   console.log(values);
// }).catch(err=>console.log(err.message));

// Promise.allSettled([promise1, promise2, promise3]).then(values => {
//   console.log('then');
//   console.log(values); // 类型是 Promise[]
// }).catch(err=>console.log(err.message));

// 谁最先返回结果values就是谁
Promise.race([promise1, promise2, promise3]).then(values => {
  console.log('then');
  console.log(values);
}).catch(err=>console.log(err.message));

